﻿using GalaSoft.MvvmLight.Command;
using Hue_Demo_PCL.Models;
using Hue_Demo_PCL.Services;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Hue_Demo_PCL.ViewModels
{
    public class HueAnimationViewModel : INotifyPropertyChanged
    {
        public HueService _hueService;
        
        public HueAnimationViewModel() { }

        public HueAnimationViewModel(HueService _hs)
        {
            _hueService = _hs;
        }

        #region HueAnimation (ObservableCollection<HueKeyFrame>)
        private ObservableCollection<HueKeyFrame> _hueAnimation = new ObservableCollection<HueKeyFrame>();
        public ObservableCollection<HueKeyFrame> HueAnimation
        {
            get{ return _hueAnimation; }
            set
            {
                _hueAnimation = value;
                RaisePropertyChanged("HueAnimation");
            }
        }
        #endregion

        #region IsAnimating (bool)
        private bool _isAnimating = false;
        public bool IsAnimating
        {
            get { return _isAnimating; }
            set
            {
                _isAnimating = value;
                RaisePropertyChanged("IsAnimating");
            }
        }
        #endregion
        
        public async Task UpdateLight(HueLight hl)
        {
            if (hl != null)
            {
                hl.UpdateHueSat();
                if (_hueService == null)
                    return;
                string result = await _hueService.SetLight(hl);
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }     
    }
}
